class Solution {
public:
	vector<vector<int> > threeSum(vector<int> &num) {

		sort(num.begin(), num.end());
		vector < vector<int>> rlt;
		for (int i = 0; i < num.size(); i++)
		{
            
            if (i> 0 && num[i] == num[i - 1]) {   ////这里写的时候漏了    过滤掉已经寻找的元组，注意 num是已经排序了的
                continue;
            }

			int target = -num[i];
			vector<int> element;
			int left = i + 1, right = num.size() - 1;
			while (left < right)
			{
				
				if (num[left] + num[right] == target)
				{
                      rlt.push_back({num[i],num[left],num[right]}); 
					while(left < right && num[left] == num[left+1])++left;  //注意这里的left ++和当前if的left++作用不一样
                    while(left < right && num[right] == num[right-1])--right;//过滤相同元组
					left++; //寻找下一组元组
                    right--;
				}
				else if (num[left] + num[right] > target)
				{
					right--;
				}
				else
				{
					left++;
				}

			}
		}
		return rlt;
	}

	};